﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UCNKompetenceBors.Database;

namespace UCNKompetenceBors.Login
{
    public partial class activateUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                unDelete.Visible = false;
                activate.Visible = false;

                //Shows controls based on the purpose query string
                switch (Request.QueryString["p"])
                {
                    case "undelete":
                        unDelete.Visible = true;
                        break;
                    case "activate":
                        activate.Visible = true;
                        break;
                    default:
                        break;
                }

                #region Globalization
                string culture = String.Empty;

                if (HttpContext.Current.Session["MyCulture"] != null)
                    culture = HttpContext.Current.Session["MyCulture"].ToString();

                if (!String.IsNullOrEmpty(culture))
                    GeneralTools.SetCulture(culture);

                LocalizeControls();
                #endregion
            }
        }

        protected void btnCancelUnDelete_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/default.aspx");
        }

        protected void btnConfirmUnDelete_Click(object sender, EventArgs e)
        {
            Guid userId = Guid.Parse(Request.QueryString["uid"]);

            //Removes the mark for deletion on a user, based on the userId
            dbLogin.UnmarkUserForDeletion(userId);
        }

        /// <summary>
        /// Localizes the controls of the site, based on the current UI Culture.
        /// </summary>
        private void LocalizeControls()
        {
            btnCancelUnDelete.Text = GetLocalResourceObject("btnCancelUnDeleteText").ToString();
            btnConfirmUnDelete.Text = GetLocalResourceObject("btnConfirmUnDeleteText").ToString();
            lblUnDelete.Text = GetLocalResourceObject("lblUnDeleteText").ToString();
        }
    }
}